package net.discard.util;

import org.apache.http.Header;
import org.apache.http.NameValuePair;
import org.apache.http.client.CookieStore;

import java.util.List;

/**
 * Created by Discard on 2017/9/14.
 */
public class HTTPBuilder {


    private String url;

    private String param;

    private List<NameValuePair> nameValuePairList;

    private Header[] headers;

    private int connectTimeout;

    private int socketTimeout;

    private CookieStore cookieStore;

    private boolean needSSL;

    private String cdn;

    private boolean needXForward;

    private String xForwardIp;

    /**
     * 是否打印正常的请求日志, 默认true, 表示要打印
     */
    private boolean log = true;

    public HTTPBuilder() {
    }

    public HTTPBuilder url(String url) {
        this.url = url;
        return this;
    }

    public HTTPBuilder param(String param) {
        this.param = param;
        return this;
    }

    public HTTPBuilder nameValuePairList(List<NameValuePair> nameValuePairList) {
        this.nameValuePairList = nameValuePairList;
        return this;
    }

    public HTTPBuilder headers(Header[] headers) {
        this.headers = headers;
        return this;
    }

    public HTTPBuilder connectTimeout(int connectTimeout) {
        this.connectTimeout = connectTimeout;
        return this;
    }

    public HTTPBuilder socketTimeout(int socketTimeout) {
        this.socketTimeout = socketTimeout;
        return this;
    }

    public HTTPBuilder cookieStore(CookieStore cookieStore) {
        this.cookieStore = cookieStore;
        return this;
    }

    public HTTPBuilder needSSL(boolean needSSL) {
        this.needSSL = needSSL;
        return this;
    }

    public HTTPBuilder log(boolean log) {
        this.log = log;
        return this;
    }

    public HTTPBuilder build() {
        return this;
    }

    public String getUrl() {
        return url;
    }

    public String getParam() {
        return param;
    }

    public Header[] getHeaders() {
        return headers;
    }

    public boolean getNeedSSL() {
        return needSSL;
    }

    public boolean getLog() {
        return log;
    }

    //    public List<NameValuePair> getNameValuePairList() {
//        return nameValuePairList;
//    }

    public int getConnectTimeout() {
        return connectTimeout;
    }

    public int getSocketTimeout() {
        return socketTimeout;
    }

    public CookieStore getCookieStore() {
        return cookieStore;
    }

    public List<NameValuePair> getNameValuePairList() {
        return nameValuePairList;
    }

    public boolean isNeedSSL() {
        return needSSL;
    }

    public HTTPBuilder cdn(String cdn) {
        this.cdn = cdn;
        return this;
    }

    public String getCdn() {
        return cdn;
    }

    public boolean isNeedXForward() {
        return needXForward;
    }

    public String getxForwardIp() {
        return xForwardIp;
    }

    public HTTPBuilder needXforward(boolean need) {
        this.needXForward = need;
        return this;
    }

    public HTTPBuilder xForwardIp(String ip) {
        this.xForwardIp = ip;
        return this;
    }

}
